package logic

import (
	"context"
	"fmt"

	"server_1.0/service/result/internal/svc"
	"server_1.0/service/result/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryClassLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQueryClassLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryClassLogic {
	return &QueryClassLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QueryClassLogic) QueryClass(in *result.QueryNoReq) (*result.QReps, error) {
	pre := "%"
	str := fmt.Sprintf("%s%s", in.No, pre)
	usersHandle := make([]*result.Reps, 0)
	count := 0
	fmt.Println(str)
	res, _ := l.svcCtx.ResultModel.FindClass(l.ctx, str)
	fmt.Println(res)
	for _, item := range res {
		usersHandle = append(
			usersHandle,
			&result.Reps{
				Code: 200,
				Time: item.Etime,
				Sno:  item.Rsno,
				Pno:  item.Rpno,
				Ans:  item.Rans,
			})
		count += 1
	}

	return &result.QReps{
		Count: int64(count),
		QRs:   usersHandle,
	}, nil
}
